<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="t" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>


<div class="row-fluid">

    <sf:form method="POST" class="form-horizontal" modelAttribute="organizacaoForm" action="save">

        <sf:hidden  path="id"/>


        <div class="control-group">
            <label class="control-label"></label>

            <div class="controls form-inline">

                <label>
                    <c:if test='${tipo == "ODSA"}'>
                        <input name="tipo" type="radio" value="ODSA" checked="true"/>
                    </c:if>
                    <c:if test='${tipo != "ODSA"}'>
                        <input name="tipo" type="radio" value="ODSA"/>
                    </c:if>
                    <span class="lbl">ODSA</span>
                </label>
                &nbsp;&nbsp;&nbsp;
                <label>
                    <c:if test='${tipo == "UNIDADE"}'>
                        <input name="tipo" type="radio" value="UNIDADE" checked="true"/>
                    </c:if>
                    <c:if test='${tipo != "UNIDADE"}'>
                        <input name="tipo" type="radio" value="UNIDADE"/>
                    </c:if>

                    <span class="lbl">Unidade</span>
                </label>
                &nbsp;&nbsp;&nbsp;
                <label>
                    <c:if test='${tipo == "EXTERNO"}'>
                        <input name="tipo" type="radio" checked="true" value="EXTERNO" />
                    </c:if>
                    <c:if test='${tipo != "EXTERNO"}'>
                        <input name="tipo" type="radio" value="EXTERNO" />
                    </c:if>


                    <span class="lbl">Externo</span>
                </label>


            </div>
        </div>


        <div class="control-group" id="parent-container">
            <label class="control-label" for="parentId">Órgao Superior</label>
            <div class="controls">

                <sf:select  path="parentId" data-placeholder="Escolha uma Organização...">
                    <sf:option value="0">&nbsp;</sf:option>
                    <c:forEach var="organizacao" items="${organizacoes}">

                        <sf:option value="${organizacao.id}">${organizacao.sigla}</sf:option>
                    </c:forEach>
                </sf:select>
            </div>
        </div>

        <div class="control-group">
            <sf:label cssClass="control-label" path="sigla">Sigla</sf:label>

                <div class="controls">
                <sf:input maxlength="255" path="sigla" placeholder="Sigla" /><br/>
                <sf:errors path="sigla" cssClass="text-error" />

            </div>
        </div>
        <div class="control-group">
            <sf:label cssClass="control-label" path="nome">Nome</sf:label>

                <div class="controls">
                <sf:input maxlength="255" path="nome" placeholder="Nome" /><br/>
                <sf:errors path="nome" cssClass="text-error" />

            </div>
        </div>
        <div class="form-actions">
            <button class="btn btn-info" type="submit">
                <i class="icon-ok bigger-110"></i>
                Gravar
            </button>

            &nbsp; &nbsp; &nbsp;
            <button class="btn" type="reset">
                <i class="icon-undo bigger-110"></i>
                Voltar
            </button>
        </div>


    </sf:form>

</div>



<!--inline scripts related to this page-->

<script type="text/javascript">
    $(function() {
        $('#parent-container').hide();
        $(".chzn-select").chosen();
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});

        $('input:radio[name=tipo]').change(function() {
            var tipo = $('input:radio[name=tipo]:checked').val();
            if (tipo == 'UNIDADE') {

                $('#parent-container').show();

            } else {
                $('#parent-container').hide();
            }
        });

    });
</script>